/*
 * author      : dormi330
 * date        : 2018/7/16
 * description : 退款申请记录
 */

package com.deep.trade.domain.refund;

public enum RefundOrderStatusEnum {

    MEMBER_APPLIED("member_applied", "用户申请"),
    MEMBER_CANCELLED("member_cancelled", "用户已撤销"),
    SELLER_ACCEPTED("seller_accpted", "卖家已同意"),
    SELLER_REJECTED("seller_rejected", "卖家已拒绝"),
    REFUND_FINISH("refund_finish", "退款已完成"),
    REFUND_DELETE("refund_delete", "退款已删除");

    public final String name;
    public final String desc;

    RefundOrderStatusEnum(String name, String desc) {
        this.name = name;
        this.desc = desc;
    }

    public static RefundOrderStatusEnum fromString(String name) {
        for (RefundOrderStatusEnum statusEnum : RefundOrderStatusEnum.values()) {
            if (statusEnum.name.equals(name))
                return statusEnum;
        }
        return null;
    }

    @Override
    public String toString() {
        return "RefundOrderStatusEnum{" +
                "name='" + name + '\'' +
                ", desc='" + desc + '\'' +
                '}';
    }

    /**
     * 是否可以转换到下一个状态
     * <p>
     * 并不想为此实现一个状态机
     */
    public boolean canChangeTo(RefundOrderStatusEnum nextStatus) {
        switch (this) {
            // 已申请 -> 用户已撤销
            //       -> 卖家已同意
            //       -> 卖家已拒绝
            case MEMBER_APPLIED:
                return nextStatus == MEMBER_CANCELLED
                        || nextStatus == SELLER_ACCEPTED
                        || nextStatus == SELLER_REJECTED;

            // 已取消 -> 已删除
            case MEMBER_CANCELLED:
                return nextStatus == REFUND_DELETE;

            // 已同意 -> 已完成
            case SELLER_ACCEPTED:
                return nextStatus == REFUND_FINISH;

            // 已拒绝 -> 已删除
            case SELLER_REJECTED:
                return nextStatus == REFUND_DELETE;

            // 已完成 -> 已删除
            case REFUND_FINISH:
                return nextStatus == REFUND_DELETE;

            // 其他状态
            default:
                return false;
        }
    }
}
